package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 陶肖寅
 * @version V1.0
 * @Package com.lagou.edu.controller
 * @date 2020-02-02 16:23
 * @Copyright © 2020-2021 城云科技(中国)有限公司
 */
@Controller
@RequestMapping("/resumes")
public class ResumeController {

    @Autowired
    ResumeService resumeService;
    @GetMapping("/addForm")
    public ModelAndView addForm() throws Exception {

        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("add");
        return modelAndView;
    }
    @GetMapping("/editForm")
    public ModelAndView editForm(Long id) throws Exception {

        Resume resume = resumeService.getResumeById(id);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("resume",resume);
        modelAndView.setViewName("edit");
        return modelAndView;
    }
    @GetMapping("")
    public ModelAndView list() throws Exception {

       List<Resume> resumes = resumeService.queryResumeList();
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("resumes",resumes);
        modelAndView.setViewName("success");

        return modelAndView;
    }
    @PostMapping("")
    public ModelAndView add(Resume resume) throws Exception {
        resumeService.saveResume(resume);
        return list();
    }
    @PutMapping("")
    public ModelAndView edit(Resume resume) throws Exception {
        resumeService.saveResume(resume);
        return list();
    }
    @DeleteMapping("/{id}")
    public ModelAndView delete(@PathVariable("id") Long id) throws Exception {
        resumeService.deleteResume(id);
        return list();
    }
}
